{	Problem: http://codechef.com/problems/MIME2/
 	Verdict: Accepted
}
const p:longint=31079;
			x:longint=264;
var i,n,m,k,index,j,cnt,r:longint; s,e,t:string; tp,res:array[0..110] of string; h:array[0..31100,0..100] of longint;
function hash(s:string):int64;
var i:longint; c,res:int64;
begin
res:=0;
c:=1;
for i:=1 to length(s) do begin
    c:=(c*x) mod p;
		inc(res,(ord(s[i])*c) mod p);
		res:=res mod p;
end;
hash:=res;
end; 
begin
readln(n,m);
tp[0]:='unknown';
fillchar(h,sizeof(h),0);
cnt:=0;
for i:=1 to n do begin
	readln(s);
	e:=copy(s,1,pos(' ',s)-1);
	delete(s,1,pos(' ',s));
	t:=s;
	k:=hash(e);
	index:=0;
	for j:=1 to h[k][0] do
		if tp[h[k][j]]=t then begin
			index:=h[k][j];
			break;
		end;
	if index=0 then begin 
		inc(cnt);
		index:=cnt;
		inc(h[k][0]);
		h[k][h[k][0]]:=index;
		tp[cnt]:=t;
		res[cnt]:=e;
	end;
end;
for i:=1 to m do begin
	r:=0;
	readln(s);
	if pos('.',s)<>0 then begin
		while pos('.',s)<>0 do delete(s,1,pos('.',s));
		k:=hash(s);
		if h[k][0]>0 then
			for j:=1 to h[k][0] do
				if res[h[k][j]]=s then r:=h[k][j];
	end;
	writeln(tp[r]);
end;
end.